package crond

import (
	"device-admin/config/redis"
	"device-admin/internal/app/grpc/service/alarm_monitor"
	"device-admin/internal/app/grpc/service/terminal"
	"device-admin/internal/app/web/service/device"
	"device-admin/internal/app/web/service/location"

	consumer "192.168.1.75/go-pkg/timer-consumer"
)

// 定时任务消费初始化
// 设备日报表，热力图，升级调度，交互主题推送
func TimerConsumerInit() {
	timerConsumer := consumer.New("system:timer-schedule:", "device-admin", redis.NewDB())
	// 清除过期的数据
	timerConsumer.AddFunc("deleteExpiredData", DelExpiredData)
	// ActiveDurationReport
	timerConsumer.AddFunc("activeDurationReport", func() error {
		ActiveDurationReport()
		return nil
	})
	// 设备日报表
	timerConsumer.AddFunc("deviceDailyReport", func() error {
		DailyReport()
		return nil
	})
	// 热力图
	timerConsumer.AddFunc("updateHeatMap", device.UpdateHeatMapConsumer)
	// 升级调度
	timerConsumer.AddFunc("terminalUpgrade", func() error {
		TerminalUpgrade()
		return nil
	})
	// 素材同步
	timerConsumer.AddFunc("themeUpgrade", func() error {
		ThemeUpgrade()
		return nil
	})
	// 离线告警检测
	timerConsumer.AddFunc("offlineCheck", alarm_monitor.AlarmMonitor{}.DstStatusCheck)
	// 更新活跃时间
	timerConsumer.AddFunc("updateTerminalActiveTime", terminal.UpdateLatestActiveTime)
	// 投放计划推送
	timerConsumer.AddFunc("advertisingPublish", func() error {
		AdvertisingPublish()
		return nil
	})
	// 每个5分钟任务
	timerConsumer.AddFunc("every5Min", location.GeoCacheCheck)
	// 定时分表
	timerConsumer.AddFunc("shardTable", DBSharding)
	// 启动定时任务消费
	timerConsumer.Start()
}
